package com.hdc.mumuwei.micro_account_server.utils;

import lombok.Data;

/**
 * @author Mumuwei
 * @Description
 * @create 2021/11/20 17:11
 */
@Data
public class Result<T> {

    public static final Integer SUCCESS_CODE = 200;
    public static final Integer ERR_CODE = 400;
    public static final Integer ERR_EXIST_CODE = 401;
    public static final Integer ERR_REQ_HEADER_CODE = 501;
    public static final Integer ERR_TOKEN_CODE = 502;

    public static final String SUCCESS_MSG = "操作成功！";
    public static final String ERR_MSG = "操作失败！";
    public static final String REGISTER_OK_MSG = "注册成功！";
    public static final String REGISTER_ERR_MSG = "注册失败，请重新注册！";
    public static final String USER_EXIST_MSG = "用户名存在";
    public static final String TYPE_EXIST_MSG = "分类存在";
    public static final String USER_NO_EXIST_MSG = "用户不存在";
    public static final String LOGIN_OK_MSG = "登录成功";
    public static final String LOGIN_ERR_MSG = "登录失败，密码错误";
    public static final String PASS_ERR_MSG = "修改失败，密码错误";
    public static final String ADD_OK_MSG = "添加成功";
    public static final String UPDATE_OK_MSG = "修改成功";
    public static final String DELETE_OK_MSG = "删除成功";
    public static final String REQUEST_HEADER_ERR_MSG = "请求参数头有误";
    public static final String TOKEN_ERR_MSG = "登陆过期，请重新登录";




    private Integer code;
    private String msg;
    private T data;

    /**
     * 默认无数据返回请求成功
     */
    public Result() {
        this.code = SUCCESS_CODE;
        this.msg = SUCCESS_MSG;
        this.data = null;
    }

    /**
     * 有数据返回请求成功
     * @param data 返回数据
     */
    public Result(T data) {
        this.code = SUCCESS_CODE;
        this.msg = SUCCESS_MSG;
        this.data = data;
    }

    /**
     * 设置消息，数据
     * @param msg 消息
     * @param data 数据
     */
    public Result(String msg,T data) {
        this.code = SUCCESS_CODE;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 无返回数据构造
     * @param code 状态码
     * @param msg 提示消息
     */
    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 全参构造
     * @param code 状态码
     * @param msg 提示消息
     * @param data 返回数据
     */
    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
}
